#ifndef _HELIX_IMAGE_TESTS_H_
#define _HELIX_IMAGE_TESTS_H_

// ImageTests.h
#include <cxxtest/TestSuite.h>
#include "../Helix/Log.h"
#include "../Helix/HObject.h"
#include "../Helix/Domain/HelixImage.h"

using namespace helix;

class ImageTest : public CxxTest::TestSuite
{
public:

	void setUp()
	{
		printf("\n\nImageTest::");
	}

	void tearDown()
	{
	}

	//This just tests the constructor of the base image class
	void testImage( void )
	{
		printf("testImage\n");
		string fileName="This does not matter.";
		Image image = Image(fileName.c_str());

		TS_ASSERT_EQUALS(0,image.getHeight());
		TS_ASSERT_EQUALS(0,image.getWidth());
		TS_ASSERT_EQUALS(0,image.getChannels());
		TS_ASSERT_EQUALS(0,image.getBitsPerPixel());
		TS_ASSERT_EQUALS(NULL,(int)image.getData());
	}

	void testOpenBMPImage( void )
	{
		printf("testOpenBMPImage\n");
		string fileName="HelixTests\\testdata\\images\\test.bmp";
		BMPImage image = BMPImage(fileName.c_str());

		TS_ASSERT_EQUALS(8,image.getHeight());
		TS_ASSERT_EQUALS(8,image.getWidth());
		TS_ASSERT_EQUALS(3,image.getChannels());
		TS_ASSERT_EQUALS(24,image.getBitsPerPixel());
		TS_ASSERT_DIFFERS(NULL,(int)image.getData());
		TS_ASSERT_EQUALS(image.getData()[0],0x00);		//Make sure red component of first pixel is 0
		TS_ASSERT_EQUALS(image.getData()[1],0x80);		//Make sure green component of first pixel is 128
		TS_ASSERT_EQUALS(image.getData()[2],0xFF);		//Make sure blue component of first pixel is 256
	}

	void testOpenTGAImage_NonRLE( void )
	{
		printf("testOpenTGAImage_NonRLE\n");
		string fileName="HelixTests\\testdata\\images\\test-NON_RLE.tga";
		TGAImage image = TGAImage(fileName.c_str());

		TS_ASSERT_EQUALS(8,image.getHeight());
		TS_ASSERT_EQUALS(8,image.getWidth());
		TS_ASSERT_EQUALS(4,image.getChannels());
		TS_ASSERT_EQUALS(32,image.getBitsPerPixel());
		TS_ASSERT_DIFFERS(NULL,(int)image.getData());
		TS_ASSERT_EQUALS(image.getData()[0],0x00);		//Make sure red component of first pixel is 0
		TS_ASSERT_EQUALS(image.getData()[1],0x80);		//Make sure green component of first pixel is 128
		TS_ASSERT_EQUALS(image.getData()[2],0xFF);		//Make sure blue component of first pixel is 256
		TS_ASSERT_EQUALS(image.getData()[3],0xFF);		//Make sure alpha component of first pixel is 256
	}

	void testOpenTGAImage_RLEEncoding( void )
	{
		printf("testOpenTGAImage_RLEEncoding\n");
		string fileName="HelixTests\\testdata\\images\\test-RLE.tga";
		TGAImage image = TGAImage(fileName.c_str());

		TS_ASSERT_EQUALS(8,image.getHeight());
		TS_ASSERT_EQUALS(8,image.getWidth());
		TS_ASSERT_EQUALS(4,image.getChannels());
		TS_ASSERT_EQUALS(32,image.getBitsPerPixel());
		TS_ASSERT_DIFFERS(NULL,(int)image.getData());
		TS_ASSERT_EQUALS(image.getData()[0],0x00);		//Make sure red component of first pixel is 0
		TS_ASSERT_EQUALS(image.getData()[1],0x80);		//Make sure green component of first pixel is 128
		TS_ASSERT_EQUALS(image.getData()[2],0xFF);		//Make sure blue component of first pixel is 256
		TS_ASSERT_EQUALS(image.getData()[3],0xFF);		//Make sure alpha component of first pixel is 256
	}

	void testOpenPNGImage( void )
	{
		printf("testOpenPNGImage\n");
		string fileName="HelixTests\\testdata\\images\\test.png";
		PNGImage *image = new PNGImage(fileName.c_str());

		TS_ASSERT_EQUALS(8,image->getHeight());
		TS_ASSERT_EQUALS(8,image->getWidth());
		TS_ASSERT_EQUALS(4,image->getChannels());
		TS_ASSERT_EQUALS(32,image->getBitsPerPixel());
		TS_ASSERT_DIFFERS(NULL,(int)image->getData());
		TS_ASSERT_EQUALS(image->getData()[0],0x00);		//Make sure red component of first pixel is 0
		TS_ASSERT_EQUALS(image->getData()[1],0x80);		//Make sure green component of first pixel is 128
		TS_ASSERT_EQUALS(image->getData()[2],0xFF);		//Make sure blue component of first pixel is 256
		TS_ASSERT_EQUALS(image->getData()[3],0xFF);		//Make sure alpha component of first pixel is 256

		delete image;
	}

	void testImageFactory_LoadBMP( void )
	{
		printf("testImageFactory_LoadBMP\n");
		string fileName="HelixTests\\testdata\\images\\test.bmp";
		Image *image = ImageFactory::loadImage(fileName.c_str());
		
		TS_ASSERT_DIFFERS(NULL,(int)image);

		ImageFactory::deleteImage(image);
	}

	void testImageFactory_LoadTGA( void )
	{
		printf("testImageFactory_LoadTGA\n");
		string fileName="HelixTests\\testdata\\images\\test-RLE.tga";
		Image *image = ImageFactory::loadImage(fileName.c_str());
		
		TS_ASSERT_DIFFERS(NULL,(int)image);

		ImageFactory::deleteImage(image);
	}

	void testImageFactory_LoadPNG( void )
	{
		printf("testImageFactory_LoadPNG\n");
		string fileName="HelixTests\\testdata\\images\\test.png";
		Image *image = ImageFactory::loadImage(fileName.c_str());
		
		TS_ASSERT_DIFFERS(NULL,(int)image);

		ImageFactory::deleteImage(image);
	}

	void testImageFactory_LoadPNG_DoesNotExist( void )
	{
		printf("testImageFactory_LoadPNG_DoesNotExist\n");
		string fileName="HelixTests\\testdata\\images\\does-not-exist.png";
		Image *image = ImageFactory::loadImage(fileName.c_str());
		
		TS_ASSERT_EQUALS(NULL,(int)image);

		ImageFactory::deleteImage(image);
	}

	void testImageFactory_InvalidExtension( void )
	{
		printf("testImageFactory_InvalidExtension\n");
		string fileName="HelixTests\\testdata\\images\\test.NotARealExtension";
		Image *image = ImageFactory::loadImage(fileName.c_str());
		
		TS_ASSERT_EQUALS(NULL,(int)image);

		ImageFactory::deleteImage(image);
	}
};

#endif